package com.lcf.myspringboot.error;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class ErrorHandler {

    //ResponseBody 返回json格式
    //modeAndView 返回页面视图
    @ResponseBody
    @ExceptionHandler(RuntimeException.class)
    public Map<String,Object> errorResultMap(){
        Map<String,Object> result=new HashMap<>();

        result.put("errCode",500);
        result.put("errMsg","全局异常捕获");

        return result;
    }
}
